package org.dromara.company.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.satoken.utils.LoginHelper;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.admin.domain.vo.UserRemarkVo;
import org.dromara.admin.domain.bo.UserRemarkBo;
import org.dromara.admin.service.IUserRemarkService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 公司端用户备注
 *
 * @author Lion Li
 * @date 2025-11-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/company/userRemark")
public class UserRemarkController extends BaseController {

    private final IUserRemarkService userRemarkService;

    /**
     * 查询自己公司的备注列表
     */
    @GetMapping("/queryMyList")
    public R<List<UserRemarkVo>> queryMyList() {
        Long userId = LoginHelper.getUserId();
        if (userId == null) {
            return R.fail("请先登录！");
        }
        List<UserRemarkVo> list = userRemarkService.queryMyList(userId);
        return R.ok(list);
    }

    /**
     * 获取用户备注详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:userRemark:query")
    @GetMapping("/{id}")
    public R<UserRemarkVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(userRemarkService.queryById(id));
    }

    /**
     * 新增用户备注
     */
//    @SaCheckPermission("system:userRemark:add")
    @Log(title = "用户备注", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody UserRemarkBo bo) {
        Long userId = LoginHelper.getUserId();
        if (userId == null) {
            return R.fail("请先登录！");
        }
        bo.setUserId(userId);
        return toAjax(userRemarkService.insertByBo(bo));
    }

    /**
     * 删除用户备注
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:userRemark:remove")
    @Log(title = "用户备注", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(userRemarkService.deleteWithValidByIds(List.of(ids), true));
    }
}
